const Koa = require('./koa')
const path = require('path')

const app = new Koa()
const port = 3000
// 引入 koa-static 中间件
const serve = require('./middleware/koa-static')
app.use(serve(path.resolve(__dirname, 'static')))

app.use(async (ctx, next) => {
    // debugger;
    // console.log(1);
    ctx.body='ok1'
     await next()
    //  debugger
    // console.log(2)
})
app.use(async (ctx,next) => {
    // debugger
    // console.log(3);
    ctx.body='ok2'
    await new Promise((resolve,reject) => {
        setTimeout(resolve(),1000)
    })
    // debugger
    await next()
    // debugger
    // console.log(4)
})
app.use(async (ctx,next) => {
    // debugger
    // console.log(5);
    // setTimeout(() => {
    //     ctx.body='ok3'
    // }, 100);
    ctx.body = 'ok3'
    await next()
    // debugger
    // console.log(6)
    // ctx.res.end('ok')
})
app.listen(port, () => {
    console.log(`${port} listen`);
})